//let start = require("./rand.js");

async function a() {
  //   let res = await start(1000);
  let red = {},
    blue = {};
  res.forEach((item) => {
    item.forEach((ball, index) => {
      if (index == 6) {
        if (blue[ball]) {
          blue[ball] += 1;
        } else {
          blue[ball] = 1;
        }
      } else {
        if (red[ball]) {
          red[ball] += 1;
        } else {
          red[ball] = 1;
        }
      }
    });
  });

  console.log("红球结果===", red);
  console.log("蓝球结果===", blue);
}

//a();

//用于生成从[min, max]范围内n个不重复随机数的函数
function randomNum(min, max, n) {
  var arr = [];
  while (arr.length < n) {
    var random = Math.floor(Math.random() * (max - min + 1) + min);
    if (arr.indexOf(random) === -1) arr.push(random);
  }
  return arr;
}

//获取红球池
function getRedBallPool() {
  var redBallPool = [];
  for (var i = 1; i <= 33; i++) {
    redBallPool.push(i);
  }
  return redBallPool;
}

//获取当前遗漏最大的蓝球号码
function getMissBlueBall(missData) {
  var maxMissIndex = 0;
  for (var i = 1; i < missData.length; i++) {
    if (missData[i] > missData[maxMissIndex]) {
      maxMissIndex = i;
    }
  }
  return maxMissIndex + 1;
}

//获取当前遗漏最大的红球号码
function getMissRedBall(missData) {
  var maxMissIndex = 0;
  for (var i = 1; i < missData.length; i++) {
    if (missData[i] > missData[maxMissIndex]) {
      maxMissIndex = i;
    }
  }
  return maxMissIndex + 1;
}

//获取蓝球池
function getBlueBallPool(missData) {
  var bluePool = [];
  var missBlueBall = getMissBlueBall(missData);
  bluePool.push(missBlueBall); //将当前遗漏最大的蓝球加入蓝球池
  return bluePool;
}

//获取经过加权后的红球号码
function getWeightedRedBall(redBallPool, missRedData) {
  var redBallOdds = []; //存储红球号码的选中概率
  var totalMiss = 0; //记录所有遗漏值的总和
  for (var i = 0; i < missRedData.length; i++) {
    totalMiss += missRedData[i];
  }
  for (var i = 0; i < redBallPool.length; i++) {
    var odds = (totalMiss - missRedData[i]) / (32 * totalMiss - totalMiss); //计算该红球号码选中的概率，采用加权方法
    redBallOdds.push(odds);
  }
  var ran = Math.random();
  var oddsIndex = 0;
  var oddsSum = redBallOdds[oddsIndex];
  while (oddsSum < ran) {
    oddsIndex++;
    oddsSum += redBallOdds[oddsIndex];
  }
  return redBallPool[oddsIndex];
}

//获取经过加权后的选票
function getWeightedBallTicket() {
  var redBallPool = getRedBallPool();
  var missRedBall = [
    3, 5, 7, 12, 16, 22, 29, 35, 42, 47, 57, 64, 74, 80, 87, 91, 95, 100, 104,
    108, 112, 116, 120, 125, 131, 140, 149, 159, 170, 181, 192, 202, 212, 222,
  ]; //假设当前红球遗漏数据
  var blueBallPool = getBlueBallPool(missRedBall);
  var blueBall = blueBallPool[Math.floor(Math.random() * blueBallPool.length)];
  var redBall = [];
  for (var i = 0; i < 6; i++) {
    var weightedRedBall = getWeightedRedBall(redBallPool, missRedBall);
    redBall.push(weightedRedBall);
    redBallPool.splice(redBallPool.indexOf(weightedRedBall), 1); //从红球池中删除已选中的红球
  }
  return {
    redBall: redBall,
    blueBall: blueBall,
  };
}

//console.log(getWeightedBallTicket());

function tt() {
  let a = [6, 2, 3, 4, 5, 6];
  let red = [2, 3, 4, 5, 7, 2];
  let oldRed = [4, 2, 2, 1, 8, 4];
  let qushi = false;
  for (let v = 0; v < red.length; v++) {
    let x = a[v] - red[v] >= 0; //新选择的值是上升还是下降
    let y = red[v] - oldRed[v] > 0; //之前中奖值是上升还是下降
    qushi = x == y;
    if (qushi) {
      //当  上升趋势相同时为不合格选号
      console.log("不合格", v);
      break;
    }
  }
  console.log("合格");
}
tt();

function efFind(arr, target) {
  let left = 0;
  let right = arr.length;
  while (left < right) {
    let mid = left + Math.floor((right - left) / 2);
    let m = arr[mid];
    if (m == target) {
      return mid;
    } else if (m > target) {
      right = mid;
    } else if (m < target) {
      left = mid + 1;
    }
  }
  return left - 1;
}
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let ac = [2, 6, 4, 3, 8, 5, 6, 7, 9, 5];
let h = [0, 2, 8, 12, 15, 23, 28, 34, 41, 50, 55];
console.log(efFind(h, 25));

console.log(new Array({ length: 33 }, (_, i) => i + 1));

let qushi = false;
let ovv = [1, 6, 2, 7, 5, 9, 3];
let vv = [2, 5, 7, 6, 4, 7, 2];
let nvv = [1, 6, 9, 7, 5, 9, 3];
for (let v = 0; v < vv.length; v++) {
  let x = nvv[v] - vv[v] >= 0; //新选择的值是上升还是下降
  let y = vv[v] - ovv[v] > 0; //之前中奖值是上升还是下降
  qushi = x == y;
  if (qushi) {
    //当  上升趋势相同时为不合格选号
    break;
  }
}
console.log(qushi);
